package com.mine.modules.vm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mine.common.domain.vo.Result;
import com.mine.modules.vm.domain.query.PersonnelPageQuery;
import com.mine.modules.vm.entity.VmAssets;
import com.mine.modules.vm.entity.VmPersonnel;
import com.mine.modules.vm.entity.VmPersonnelDepart;
import com.mine.modules.vm.mapper.VmPersonnelMapper;
import com.mine.modules.vm.service.IVmPersonnelService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xujf
 * @since 2024-12-24
 */
@Service
public class VmPersonnelServiceImpl extends ServiceImpl<VmPersonnelMapper, VmPersonnel> implements IVmPersonnelService {

    @Override
    public Result<?> pageListPersonnel(PersonnelPageQuery pageQuery) {
        LambdaQueryWrapper<VmPersonnel> queryWrapper = new LambdaQueryWrapper<>(VmPersonnel.class);
        queryWrapper.select(VmPersonnel::getId,VmPersonnel::getRealName);
        if(StringUtils.isNotBlank(pageQuery.getKeywords())){
            queryWrapper.and(e->e.like(VmPersonnel::getRealName, pageQuery.getKeywords()));
        }
        if(StringUtils.isNotBlank(pageQuery.getDepartId())){
            queryWrapper.eq(VmPersonnel::getDepartmentId, pageQuery.getDepartId());
        }
        Page<VmPersonnel> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
        return Result.ok(this.page(page, queryWrapper));
    }
}
